$(".project-experience-show").hide();
var experList = new Array();
//打开新增项目经验
function openaddProject() {
    $(".add-project").css("display","block")
    $(".project-experience-show").hide();
    $(".project-experience").show();
    $(".project-exper-key").val("");
}
/********************************************保存添加项目经验 *************************************/
$(".project-expr-save").click(function () {

    saveprojectExperience();
});


/***************************************ajax 添加新的工作经验****************************************/
function saveprojectExperience(){

    var company = $(".companyname-project").val();

    var startprojecttime = $(".starttime-project").val()
    var endprojectTime = $(".endtime-project").val()

    var projectname = $(".projectname").val();
    var projectDescription = $("#project-des").val();
    var dutyDescription = $("#duty-des ").val();

    $.ajax({
        type:"post",
        url:"/projectExperience",
        datatype:"json",
        data:{
            "resumeId":$(".resumeId").val(),
            "companyName":company,
            "startprojecttime":startprojecttime,
            "endprojectTime":endprojectTime,
            "projectname":projectname,
            "projectDescription":projectDescription,
            "dutyDescription":dutyDescription
        },
        success:function(result){
            console.log(result);
            if(result.status ==1){
                console.log("添加成功");
                $(".add-experience").css("display","none")
                $(".project-experience-show").show();  // 显示读取模式
                $(".project-experience").hide(); //隐藏编辑模式
                var experience = result.data;
                var experienceArr = new Array(experience)
                initproExe(experienceArr);//数据显示出来
            }else{
                console.log("添加失败");
            }
        }
    })
}


function initproExe(experList) {

    document.querySelector(".add-project").innerHTML = "";
    for (var i = 0; i < experList.length; i++) {
        var exper = experList[i];
        console.log("resume Id **:" + exper.resumeId)

        var time = getFormatDateYM(new Date(exper.projectStartTime)) + "-" +getFormatDateYM(new Date(exper.projectEndTime));
        console.log("time = " + time)

        var addEle="<div class=\"project-datail\"><p>公司：<span>"+exper.projectCompanyName+"</span></p>\n" +
            "                <p>时间：<span>"+time+"</span></p>\n" +
            "                <p>项目名：<span>"+exper.projectCompanyName+"</span></p>\n" +
            "                <p>项目描述：<span>"+exper.projectContentDesc+"</span></p>\n" +
            "                <p>责任描述：<span>"+exper.projectDutyDesc+"</span></p> " +
            "                <button class=\"delete-experience\" onclick=\"getByProId4Update("+exper.projectExperiId+")\">修改</button>\n" +
            "                <button class=\"\" onclick=\"\">删除</button>\n" +
            "                </div>";
        document.querySelector(".add-project").innerHTML += addEle;
    }
}

$(".project-expr-unsave").click(function () {
    $(".add-project").css("display","none")
    $(".project-experience-show").show();
    $(".project-experience").hide();
});


/*********************************************点击 修改工作经验的按钮update_workexperience_btn ***********************************************/
function getByProId4Update(projectExperiId){
    //ajax 请求 根据当前工作经验ID 查询该id

    console.log("***************projectExperiId:"+id);
    $.ajax({
        type:"get",
        url:"/projectExperience/"+id,
        datatype:"json",
        success:function(result){
            console.log(result);
            if(result.status ==1){
                //打开编辑模式
                //隐藏只读模式
                $(".add-project").css("display","none")
                $(".project-experience-show").hide();
                $(".project-experience").show();
                //并且 在保存按钮上加上class="update-work-expericen-btn"

                var updateBtn = "<button  class=\"update-work_btn\" onclick=\"updatePRO("+projectExperiId+ ")\">修改</button>";
                $(".project-expr-save").hide();
                $(".project-expr-btn-container").append(updateBtn);
            }
        }

    })
}

/*==============修改功能 ajax====================*/
function updatePRO(projectExperiId){

    var company = $(".companyname-project").val();

    var startprojecttime = $(".starttime-project").val()
    var endprojectTime = $(".endtime-project").val()

    var projectname = $(".projectname").val();
    var projectDescription = $("#project-des").val();
    var dutyDescription = $("#duty-des ").val();

    $.ajax({
        type:"post",
        url:"/projectExperience",
        datatype:"json",
        data:{
            _method:"put",
            "projectExperiId":projectExperiId,
            "companyName":company,
            "startprojecttime":startprojecttime,
            "endprojectTime":endprojectTime,
            "projectname":projectname,
            "projectDescription":projectDescription,
            "dutyDescription":dutyDescription
        },
        success:function(result){
            console.log(result);

            if(result.status ==1){
                console.log("修改成功");
                $(".add-experience").css("display","none")
                $(".project-experience-show").show();  // 显示读取模式
                $(".project-experience").hide(); //隐藏编辑模式
                var experience = result.data;
                var experienceArr = new Array(experience)
                initExper(experienceArr);//数据显示出来
            }else{
                console.log("修改失败");
            }

        }
    })
}

